package com.mxw.account.service.strategy.document;

import com.mxw.account.dto.AccountDTO;
import com.mxw.account.service.DocumentStrategy;
import com.mxw.commons.errorcode.GlobalErrorCode;
import com.mxw.commons.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

/** @Description TODO @Author RingKo @Date 2022/7/7 16:38 @Version 1.0 */
@Component
public class DocumentStrategyContainer {
  @Autowired Map<String, DocumentStrategy> documentStrategyMap;

  public String handle(String param, AccountDTO accountDTO) {
    DocumentStrategy documentStrategy =
        Optional.ofNullable(documentStrategyMap.get(param))
            .orElseThrow(() -> new CustomException(GlobalErrorCode.DATA_NOT_FOUND, "未查询到关联策略"));
    return documentStrategy.handle(accountDTO);
  }
}
